package com.yuji.aacar.net.convertfactory;

import com.google.gson.Gson;
import com.google.gson.TypeAdapter;
import com.yuji.aacar.core.cores.utils.LogUtil;

import java.io.IOException;

import okhttp3.ResponseBody;
import retrofit2.Converter;

/**
 * <li>Date: 2017/6/7
 * <li>Description:
 */
public class JsonNoSecretResponseConverter<T> implements Converter<ResponseBody, T> {
    private final Gson mGson;//gson对象
    private final TypeAdapter<T> adapter;

    /**
     * 构造器
     */
    public JsonNoSecretResponseConverter(Gson gson, TypeAdapter<T> adapter) {
        this.mGson = gson;
        this.adapter = adapter;
    }

    /**
     * 转换
     *
     * @param responseBody 业务对象
     * @return
     * @throws IOException
     */
    @Override
    public T convert(ResponseBody responseBody) throws IOException {

        String response = responseBody.string();

        LogUtil.e("result", "result ##：" + response);
        return adapter.fromJson(response);
    }

}
